package com.zhuxiaomei.result;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author hxm
 * @date 2024/5/6 20:15
 * @description
 */
@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {
    private String code;
    private String message;
    private T data;
    private long timestamp;

    public Result(){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data){
        Result result = new Result();
        result.setCode(ReturnCodeEnum.RC200.getCode());
        result.setMessage(ReturnCodeEnum.RC200.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String code, String message){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }
}
